package main

import "fmt"

//返回一个值
func plus(a int, b int) int {
	return a + b
}

//返回多个值
func vals(a int, b int) (int, int) {
	return a, b
}

//变参函数
func sum(nums ...int) {
	fmt.Print(nums, " ")
	total := 0
	for _, num := range nums {
		total += num
	}
	fmt.Println(total)
}

//闭包
func intSeq() func() int {
	i := 0
	return func() int {
		i += 1
		return i
	}
}

//递归
func fact(n int) int {
	if n == 0 {
		return 1
	}
	return n * fact(n-1)
}

func split(sum int) (x, y int) {
	x = sum * 4 / 9
	y = sum - x
	return
}

func main() {
	res := plus(5, 6)
	fmt.Println("5+6 =", res)

	a, b := vals(5, 6)
	fmt.Println(a)
	fmt.Println(b)

	_, c := vals(5, 6)
	fmt.Println(c)

	sum(1, 2)
	sum(1, 2, 3)
	nums := []int{1, 2, 3, 4}
	sum(nums...)

	nextInt := intSeq()

	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(nextInt())

	newInts := intSeq()
	fmt.Println(newInts())

	fmt.Println(fact(7))

	fmt.Println(split(17))
}
